﻿using System;
using System.CodeDom.Compiler;
using System.Diagnostics;
using Google.Protobuf;
using Google.Protobuf.Collections;
using Google.Protobuf.Reflection;

namespace EggLink.DanhengServer.Proto
{
    // 服务器调度信息协议类（Protobuf生成）
    [DebuggerDisplay("{ToString(),nq}")]
    public sealed class Dispatch : IMessage<Dispatch>, IMessage, IEquatable<Dispatch>, IDeepCloneable<Dispatch>, IBufferMessage
    {
        // Protobuf解析器实例
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public static MessageParser<Dispatch> Parser { get { return _parser; } }

        // Protobuf消息描述符（反射用）
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public static MessageDescriptor Descriptor { get { return DispatchReflection.Descriptor.MessageTypes[0]; } }

        // 显式接口实现
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        MessageDescriptor IMessage.Descriptor { get { return Descriptor; } }

        // 默认构造函数
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public Dispatch () { }

        // 拷贝构造函数（深拷贝）
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public Dispatch (Dispatch other) : this()
        {
            retcode_ = other.retcode_;
            msg_ = other.msg_;
            topSeverRegionName_ = other.topSeverRegionName_;
            regionList_ = other.regionList_.Clone();
            stopDesc_ = other.stopDesc_;
            _unknownFields = UnknownFieldSet.Clone(other._unknownFields);
        }

        // 克隆方法
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public Dispatch Clone () { return new Dispatch(this); }

        // 返回码字段（0=成功）
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public uint Retcode
        {
            get { return retcode_; }
            set { retcode_ = value; }
        }

        // 消息文本字段
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public string Msg
        {
            get { return msg_; }
            set { msg_ = ProtoPreconditions.CheckNotNull(value, "value"); }
        }

        // 主服务器区域名字段
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public string TopSeverRegionName
        {
            get { return topSeverRegionName_; }
            set { topSeverRegionName_ = ProtoPreconditions.CheckNotNull(value, "value"); }
        }

        // 服务器区域列表（只读）
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public RepeatedField<RegionInfo> RegionList { get { return regionList_; } }

        // 停服描述字段
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public string StopDesc
        {
            get { return stopDesc_; }
            set { stopDesc_ = ProtoPreconditions.CheckNotNull(value, "value"); }
        }

        // 对象比较方法
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public override bool Equals (object other) { return Equals(other as Dispatch); }

        // 强类型比较方法
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public bool Equals (Dispatch other)
        {
            return other != null &&
                   (ReferenceEquals(this, other) ||
                   (Retcode == other.Retcode &&
                    Msg == other.Msg &&
                    TopSeverRegionName == other.TopSeverRegionName &&
                    regionList_.Equals(other.regionList_) &&
                    StopDesc == other.StopDesc &&
                    object.Equals(_unknownFields, other._unknownFields)));
        }

        // 哈希码生成
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public override int GetHashCode ()
        {
            int hash = 1;
            if (Retcode != 0) hash ^= Retcode.GetHashCode();
            if (Msg.Length != 0) hash ^= Msg.GetHashCode();
            if (TopSeverRegionName.Length != 0) hash ^= TopSeverRegionName.GetHashCode();
            hash ^= regionList_.GetHashCode();
            if (StopDesc.Length != 0) hash ^= StopDesc.GetHashCode();
            if (_unknownFields != null) hash ^= _unknownFields.GetHashCode();
            return hash;
        }

        // JSON格式化输出（调试用）
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public override string ToString () { return JsonFormatter.ToDiagnosticString(this); }

        // Protobuf序列化方法
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public void WriteTo (CodedOutputStream output) { output.WriteRawMessage(this); }

        // 底层序列化实现
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        void IBufferMessage.InternalWriteTo (ref WriteContext output)
        {
            if (Retcode != 0)
            {
                output.WriteRawTag(8);
                output.WriteUInt32(Retcode);
            }
            if (Msg.Length != 0)
            {
                output.WriteRawTag(18);
                output.WriteString(Msg);
            }
            if (TopSeverRegionName.Length != 0)
            {
                output.WriteRawTag(26);
                output.WriteString(TopSeverRegionName);
            }
            regionList_.WriteTo(ref output, _repeated_regionList_codec);
            if (StopDesc.Length != 0)
            {
                output.WriteRawTag(42);
                output.WriteString(StopDesc);
            }
            if (_unknownFields != null)
            {
                _unknownFields.WriteTo(ref output);
            }
        }

        // 计算序列化后的字节大小
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public int CalculateSize ()
        {
            int size = 0;
            if (Retcode != 0) size += 1 + CodedOutputStream.ComputeUInt32Size(Retcode);
            if (Msg.Length != 0) size += 1 + CodedOutputStream.ComputeStringSize(Msg);
            if (TopSeverRegionName.Length != 0) size += 1 + CodedOutputStream.ComputeStringSize(TopSeverRegionName);
            size += regionList_.CalculateSize(_repeated_regionList_codec);
            if (StopDesc.Length != 0) size += 1 + CodedOutputStream.ComputeStringSize(StopDesc);
            if (_unknownFields != null) size += _unknownFields.CalculateSize();
            return size;
        }

        // 反序列化方法
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public void MergeFrom (CodedInputStream input) { input.ReadRawMessage(this); }

        // 底层反序列化实现
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        void IBufferMessage.InternalMergeFrom (ref ParseContext input)
        {
            uint tag;
            while ((tag = input.ReadTag()) != 0)
            {
                switch (tag)
                {
                    case 8:
                        Retcode = input.ReadUInt32();
                        break;
                    case 18:
                        Msg = input.ReadString();
                        break;
                    case 26:
                        TopSeverRegionName = input.ReadString();
                        break;
                    case 34:
                        regionList_.AddEntriesFrom(ref input, _repeated_regionList_codec);
                        break;
                    case 42:
                        StopDesc = input.ReadString();
                        break;
                    default:
                        _unknownFields = UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                        break;
                }
            }
        }

        // 对象合并方法
        [DebuggerNonUserCode]
        [GeneratedCode("protoc", null)]
        public void MergeFrom (Dispatch other)
        {
            if (other == null) return;
            if (other.Retcode != 0) Retcode = other.Retcode;
            if (other.Msg.Length != 0) Msg = other.Msg;
            if (other.TopSeverRegionName.Length != 0) TopSeverRegionName = other.TopSeverRegionName;
            regionList_.Add(other.regionList_);
            if (other.StopDesc.Length != 0) StopDesc = other.StopDesc;
            _unknownFields = UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        // 私有字段（严格保持原始声明顺序）
        private static readonly MessageParser<Dispatch> _parser = new MessageParser<Dispatch>(() => new Dispatch());
        private UnknownFieldSet _unknownFields;
        private uint retcode_;
        private string msg_ = "";
        private string topSeverRegionName_ = "";
        private static readonly FieldCodec<RegionInfo> _repeated_regionList_codec = FieldCodec.ForMessage<RegionInfo>(34, RegionInfo.Parser);
        private readonly RepeatedField<RegionInfo> regionList_ = new RepeatedField<RegionInfo>();
        private string stopDesc_ = "";
    }
}